using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using MiragePWF.Common.Container;
using Wolfut.MirageEE.Domain.Common;
using Wolfut.MirageEE.Domain.CommonUtilities;
using Wolfut.MirageEE.Interface.Common;
using Wolfut.MirageEE.UI.UIBaseComponents;
using Wolfut.MirageEE.UI.UICommonUtilities;

namespace Wolfut.MirageEE.UI.UI.Common
{
    /// <summary>
    /// todo 1:UI change workflow 2:data rowindex 3:enity validation 4:exception hanlder 5:form closing
    /// 
    /// </summary>
    public partial class BillCodeRuleForm : MirageEEFormBase
    {
        public BillCodeRuleForm()
        {
            InitializeComponent();
            this.Init();
        }       

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.barButtonItemDeleteAll.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemAllDelete_ItemClick);
            this.barButtonItemExcel.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemExcel_ItemClick);
            this.barButtonItemHtml.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemHtml_ItemClick);
            this.barButtonItemText.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemText_ItemClick);
        }
        private void Init()
        {
            ucCollectBill.CodeFlag = Constant.CodeRuleConst.COLLECTING_BILLS;
            ucExpenseBill.CodeFlag = Constant.CodeRuleConst.EXPENSE_BILLS;
            ucInWareHouseOrders.CodeFlag = Constant.CodeRuleConst.IN_WAREHOUSE_ORDERS;
            ucOtherCollectingBills.CodeFlag = Constant.CodeRuleConst.OTHER_COLLECTING_BILLS;
            ucOutWareHouseOrders.CodeFlag = Constant.CodeRuleConst.OUT_WAREHOUSE_ORDERS;
            ucPayMentBills.CodeFlag = Constant.CodeRuleConst.PAYMENT_BILLS;
            ucProductTransferBill.CodeFlag = Constant.CodeRuleConst.PRODUCT_TRANSFER_BILLS;
            ucProductTransferBillMode.CodeFlag = Constant.CodeRuleConst.PRODUCT_TRANSFER_BILLS_MODE;
            ucPurchaseBill.CodeFlag = Constant.CodeRuleConst.PURCHASE_BILLS;
            ucPurChaseOrders.CodeFlag = Constant.CodeRuleConst.PURCHASE_ORDERS;
            ucPurchaseReturn.CodeFlag = Constant.CodeRuleConst.PURCHASE_GOODS_RETURNED_ORDERS;
            ucSaleBill.CodeFlag = Constant.CodeRuleConst.SALES_BILLS;
            ucSaleOrders.CodeFlag = Constant.CodeRuleConst.SALES_ORDERS;
            ucSaleReturn.CodeFlag = Constant.CodeRuleConst.SALES_RETURN_BILLS;
            ucWareTransferBill.CodeFlag = Constant.CodeRuleConst.WARE_TRANSFER_BILLS;
            ucVoucherNO.CodeFlag = Constant.CodeRuleConst.VOUCHER_NO;
            foreach (Control item in TabControlBillCodeRule.TabPages)
            {
                foreach (Control subItem in item.Controls)
                {
                    if (subItem is UserBillCodeRuleControl)
                    {
                        item.Text = Constant.CodeRuleConst.GetCodeRuleFlagName(((UserBillCodeRuleControl)subItem).CodeFlag);
                        break;
                    }
                }
            }
        }

        private UserBillCodeRuleControl SelectedPageFindControl()
        {
            foreach (Control item in this.TabControlBillCodeRule.SelectedTabPage.Controls)
            {
                if (item is UserBillCodeRuleControl)
                {
                    return (UserBillCodeRuleControl)item;
                }
            }
            return null;
        }
        private void barButtonItemAllDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SelectedPageFindControl().OnAllDeleted(e);
        }
        private void barButtonItemExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag));
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_EXCEL, SelectedPageFindControl().GridCodeRule);
        }       
        private void barButtonItemHtml_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag));
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_HTML, SelectedPageFindControl().GridCodeRule);
        }
        private void barButtonItemText_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag));
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_TEXT, SelectedPageFindControl().GridCodeRule);
        }
        private void simpleButtonHelp_Click(object sender, EventArgs e)
        {
            base.HelpMe(this.Name);
        }

        private void simpleButtonChoose_Click(object sender, EventArgs e)
        {

        }

        private void simpleButtonClose_Click(object sender, EventArgs e)
        {
            base.CloseMe();
        }    
    }
}